<template>
  <el-dialog :visible.sync="localVisible" title="状态变更历史" width="60%">
    <div v-if="history && history.length">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in history"
          :key="index"
          :timestamp="item.createdAt"
        >
          {{ item.modifiedByName }} 将状态从 "{{ getDisplayName(item.oldStatus) }}" 变更为 "{{ getDisplayName(item.newStatus) }}" —— 备注：{{ item.remark }}
        </el-timeline-item>
      </el-timeline>
    </div>
    <el-empty v-else description="暂无状态变更历史" :image-size="200"></el-empty>
  </el-dialog>
</template>

<script>
export default {
  name: 'StatusHistoryDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    history: {
      type: Array,
      default: () => []
    },
    orderState: { // 添加 orderState 的 prop 定义
      type: Array,
      required: true
    }
  },
  computed: {
    localVisible: {
      get() {
        return this.visible;
      },
      set(value) {
        this.$emit('update:visible', value);
      }
    }
  },
  methods: {
    getDisplayName(statusIndex) {
      return this.orderState[statusIndex] || '未知状态';
    }
  }
};
</script>